package com.qb.mobile.ui;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.qb.mobile.R;
import com.qb.mobile.model.Phonebook;

/**
 * @author <a href="mailto:dangcongthanhtrung@gmail.com">dangtrung</a>
 * 
 *         RssListItem.java class
 * 
 */
public class PhoneSystemListItem extends RelativeLayout {

	public PhoneSystemListItem(Context context, AttributeSet attrs) {
		super(context, attrs);
	}

	/**
	 * @param phonebook
	 */
	public void setPhoneBookInfo(Phonebook phonebook) {
		if (null != phonebook) {
			TextView tvName = (TextView) findViewById(R.id.txtName);
			tvName.setText("Name : " + phonebook.getName());
			
			TextView tvPhone = (TextView) findViewById(R.id.txtPhoneHome);			
			tvPhone.setText("Phone : " + phonebook.getPhones().get(0).getNumber());
			
			ImageView image = (ImageView) findViewById(R.id.image);
			if(phonebook.getPhoto() != null){
				byte[] photoBlob = phonebook.getPhoto().getPhoto();
				Bitmap photoBitmap = BitmapFactory.decodeByteArray(photoBlob, 0,
						photoBlob.length);
				image.setImageBitmap(photoBitmap);
			} else 
				image.setBackgroundResource(R.drawable.ic_contact_picture);
			
			ImageView imageNext = (ImageView) findViewById(R.id.imageNext);
			imageNext.setBackgroundResource(R.drawable.btn_next_default);
			
			
		}
	}
}
